package com.mooc.ppjoke.ui.detail;

import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.mooc.ppjoke.R;
import com.mooc.ppjoke.data.Feed;
import com.mooc.ppjoke.databinding.ActivityFeedDetailTypeImageBinding;
import com.mooc.ppjoke.databinding.LayoutFeedDetailTypeImageHeaderBinding;
import com.mooc.ppjoke.ui.my_view.NetImageView;

import org.jetbrains.annotations.NotNull;

/**
 * @ClassName: ImageViewHander$
 * @Description: java类作用描述
 * @Author: 魏靳元
 * @CreateDate: 2022/8/26 08:18
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class ImageViewHandler extends ViewHandler {

    protected   ActivityFeedDetailTypeImageBinding binding;
    protected LayoutFeedDetailTypeImageHeaderBinding headerBinding;

    public ImageViewHandler(FragmentActivity activity) {
        super(activity);
        binding = DataBindingUtil.setContentView(activity, R.layout.layout_feed_type_image);
        binding.setFeed(mFeed);
        mBottomBinding=binding.bottomInteractionLayout;
    }

    @Override
    public void bindInitData(Feed feed) {
        super.bindInitData(feed);

        headerBinding = LayoutFeedDetailTypeImageHeaderBinding.inflate(LayoutInflater.from(activity), rv, false);
        headerBinding.setFeed(feed);
        NetImageView headerImage = headerBinding.headerImage;
        headerImage.bindData(mFeed.width, mFeed.height, mFeed.width>mFeed.height?0:16, mFeed.cover);
        adapter.addHeaderView(headerBinding.getRoot());
        rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(@NonNull @NotNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                boolean visible = headerBinding.getRoot().getTop() <= -binding.titleLayout.getMeasuredHeight();
                if (visible){
                    binding.authorInfoLayout.getRoot().setVisibility(View.VISIBLE);
                    binding.title.setVisibility(View.GONE);
                }else {
                    binding.authorInfoLayout.getRoot().setVisibility(View.GONE);
                    binding.title.setVisibility(View.VISIBLE);
                }
            }
        });
        handleEmpty(false);
    }

}
